package com.eight.statistics.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.eight.statistics.dao.MemberDao;
import com.eight.statistics.pojo.Member;
import com.eight.statistics.pojo.MemberType;
import com.eight.statistics.service.MemberService;
import com.eight.statistics.vo.ChartTimeVo;
import com.eight.statistics.vo.TimeVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @program: qy8-education
 * @description:
 * @author: 郑友民（1460115388@qq.com）
 * @create: 2023-05-27 16:55
 **/
@Service
public class MemberServiceImpl implements MemberService {
    @Resource
    private MemberDao memberDao;


    @Override
    public List<MemberType> queryMemberTypeBang(ChartTimeVo chartTimeVo) {
        QueryWrapper<Member> wrapper = new QueryWrapper<>();
        if (chartTimeVo.getGmtCreate() != null) {
            wrapper.ge("gmt_modified", chartTimeVo.getGmtCreate());
        }
        if (chartTimeVo.getGmtModified() != null) {
            wrapper.le("gmt_modified", chartTimeVo.getGmtModified());
        }
        wrapper.eq("is_deleted",0);
        List<Member> members = memberDao.selectList(wrapper);
        long count = members.stream().filter(item -> item.getIsType() == 0).count();
        long count1 = members.stream().filter(item -> item.getIsType() == 1).count();
        List<MemberType> memberTypes = new ArrayList<>();
        memberTypes.add(new MemberType("会员", count));
        memberTypes.add(new MemberType("讲师", count1));
        return memberTypes;
    }
}

